// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html

cc.Class({
    extends: cc.Component,

    properties: {
        className: "HomeScene",
        joinRoom: {
            default: null,
            type: cc.Prefab
        },
    },
    onPlay: function (evnet, customData) {
        var data = {};
        data.mapId = Number(customData);
        network.send("createRoom", data);
    },
    onClick: function (evnet, customData) {
        if (customData === "wanfa") {

        } else if (customData === "message") {

        } else if (customData === "zhanji") {

        } else if (customData === "fenxiang") {

        } else if (customData === "shezhi") {

        } else if (customData === "joinroom") {
            var joinRoom = cc.instantiate(this.joinRoom);
            joinRoom.parent = this.node;
        } else if (customData == "shop") {
        }
    },
    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        var self = this;
        network.addListener(this.className, "joinRoom", function (data) {
            console.log("HomeScene: joinRoom");
            // 预加载场景
            network.stop();
            network.removeListener(self.className);
            // cc.director.preloadScene("PokerScene_psz", function () {
            cc.director.loadScene("PokerScene_psz", function () {
                var messageObj = {};
                messageObj.code = "joinRoom";
                messageObj.data = data;
                network.recv(messageObj);
            });
            // });
        });
        network.addListener(this.className, "createRoom", function (data) {
        });
    },

    start() {

    },

    // update (dt) {},
});
